{% extends "base.html" %}
{% if not title %}
  {% set title = _('{title} | Media Gallery')|f(title=media.title) %}
{% endif %}
{% set styles = ('gallery',) %}
{% set scripts = ('wiki',) %}
{% if not crumbs %}
  {% set crumbs = [(url('gallery.gallery', media_type), _('Media Gallery')),
                   (None, media.title)] %}
{% endif %}
{% set delete_this = _('Delete this image') %}
{% set edit_this = _('Edit this image') %}

{% set meta = [('robots', 'noindex')] %}

{% block above_main %}
  {% if user.is_authenticated() %}
    <a id="btn-upload" class="btn btn-submit" href="{{ url('gallery.gallery', media_type)|urlparams(hash='upload') }}">{{ _('Upload a New Media File') }}</a>
  {% endif %}
  <h1>{{ media.title|truncate(length=55, killwords=True) }}</h1>
{% endblock %}

{% block content %}
  <div id="media-object" class="main grid_12">
    <div class="content-box">
      <div id="media-metainfo">
        <ul id="media-info" class="cf">
          {% if media_type =='image' %}
            <li class="dimensions">
              {{ media.file.width }} x {{ media.file.height }} px
            </li>
            <li class="size">
              {{ media.file.size // 1024 }} KB
            </li>
            {% else %}{# video #}
            {% if media.flv %}
              <li class="format-flv">
                FLV ({{ media.flv.size // 1024 }} KB)
              </li>
            {% endif %}
            {% if media.ogv %}
              <li class="format-ogv">
                OGV ({{ media.ogv.size // 1024 }} KB)
              </li>
            {% endif %}
            {% if media.webm %}
              <li class="format-webm">
                WEBM ({{ media.webm.size // 1024 }} KB)
              </li>
            {% endif %}
          {% endif %}
          {% if media_format %}
            <li class="format">{{ media_format|upper }}</li>
          {% endif %}
        </ul>
        <ul id="media-meta" class="cf">
          <li class="creator">
              {{ _('by <a href="{profile_url}">{user}</a>')|fe
                      (profile_url=profile_url(media.creator),
                      user=display_name(media.creator)) }}
          </li>
          <li class="created">{{ _('Uploaded {date}')|fe(date=datetimeformat(media.created, format='datetime')) }}</li>
          <li class="locale">{{ settings.LANGUAGES_DICT[media.locale.lower()] }}</li>
        </ul>
      </div>
      <div id="media-view">
        {% if media_type == 'image' %}
          <img src="{{ media.file.url }}" alt="{{ media.title }}" />
        {% else %}
          {{ generate_video(media) }}
        {% endif %}
      </div>

      <h2>{{ _('Description') }}</h2>
      <div class="description">{{ media.description|wiki_to_html }}</div>

      {% if media_type == 'image' %}
        <h2>{{ _('Articles') }}</h2>
        {% set documents = media.documents %}
        <div class="documents">
          {% if documents %}
            <p>{{ _('The following articles include this image:') }}</p>
            <ul>
              {% for doc in documents %}
                <li><a href="{{ doc.get_absolute_url() }}">{{ doc.title }}</a></li>
              {% endfor %}
            </ul>
          {% else %}
            <p>{{ _('This image is not included in any articles.') }}</p>
          {% endif %}
        </div>
      {% endif %}
    </div>
    <div class="submit">
      <form id="media-actions" action="{{ url('gallery.delete_media', media_type, media.pk) }}" method="GET">
        {% if user == media.creator or
          (media_type == 'image' and user.has_perm('gallery.delete_image')) or
          (media_type == 'video' and user.has_perm('gallery.delete_video')) %}
          <button type="submit" class="btn btn-submit big">{{ delete_this }}</button>
        {% endif %}
        {% if media_type == 'image' and (user == media.creator or user.has_perm('gallery.change_image')) %}
          <a class="btn" href="{{ url('gallery.edit_media', media_type, media.id) }}">{{ edit_this }}</a>
        {% endif %}
      </form>
    </div>
  </div>
{% endblock %}
